package com.seal.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.seal.comm.utils.Page;
import com.seal.dao.IUserInfoDao;
import com.seal.dto.UserInfoDto;
import com.seal.model.UserInfo;
import com.seal.service.IUserInfoService;

@Service("userInfoServiceImpl")
@Transactional(readOnly = false)
public class UserInfoServiceImpl implements IUserInfoService {

	@Resource(name = "userInfoDaoImpl")
	private IUserInfoDao userInfoDao;

	@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
	public void addUserInfo(UserInfo ca) throws Exception{
		userInfoDao.addUserInfo(ca);
	}

	@Transactional(propagation = Propagation.REQUIRED,readOnly = false, rollbackForClassName = "Exception")
	public void deleteUserInfo(UserInfo ca) throws Exception {
		userInfoDao.deleteUserInfo(ca);
	}

	public List<UserInfo> getAllUserInfo(UserInfoDto userInfoDto, Page page)
			throws Exception {
		return userInfoDao.getAllUserInfo(userInfoDto, page);
	}

	public List<String> getLowerUserStrIds(UserInfo userInfo) throws Exception {
		List<String> lowerUserIds=new ArrayList<String>();
		List<UserInfo> userList=userInfoDao.getLowerUsers(userInfo);
		for(UserInfo user:userList){
			lowerUserIds.add(user.getUserId());
		}
		return lowerUserIds;
	}
	
	public List<Long> getLowerUserIds(UserInfo userInfo) throws Exception{
		List<Long> lowerUserIds=new ArrayList<Long>();
		List<UserInfo> userList=userInfoDao.getLowerUsers(userInfo);
		for(UserInfo user:userList){
			lowerUserIds.add(user.getId());
		}
		return lowerUserIds;
	}

	public UserInfo getUserInfoById(Long id) throws Exception {
		return userInfoDao.getUserInfoById(id);
	}

	public UserInfo getUserInfoByUserId(String userId)
			throws Exception {
		return userInfoDao.getUserInfoByUserId(userId);
	}

	@Transactional(propagation = Propagation.REQUIRED,readOnly = false, rollbackForClassName = "Exception")
	public void updateUserInfo(UserInfo ca) throws Exception {
		userInfoDao.updateUserInfo(ca);
	}

	public Integer getUserInfoCount(UserInfoDto userInfoDto) throws Exception {
		return userInfoDao.getUserInfoCount(userInfoDto);
	}

	public boolean checkEmailExists(String userId,String email) throws Exception {
		return userInfoDao.checkEmailExists(userId,email);
	}

	public UserInfo getUserInfoByActivecode(String activeCode) throws Exception {
		return userInfoDao.getUserInfoByActivecode(activeCode);
	}

}
